package com.goods.business.service.imp;

import com.goods.business.mapper.ConsumerMapper;
import com.goods.business.service.ConsumerService;
import com.goods.common.model.business.Consumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;

@Service
public class ConsumerServiceImpl implements ConsumerService {

    @Autowired
    private ConsumerMapper consumerMapper;

    @Override
    public List<Consumer> findConsumerList(String name, String contact, String address) {
        List<Consumer> consumerList = consumerMapper.findConsumerList(name,contact,address);
        return consumerList;
    }

    @Override
    public void add(Consumer consumer) {
        consumer.setCreateTime(Calendar.getInstance().getTime());
        consumer.setModifiedTime(Calendar.getInstance().getTime());
        consumerMapper.insert(consumer);
    }

    @Override
    public Consumer edit(Long id) {
        Consumer consumer = consumerMapper.selectByPrimaryKey(id);
        return consumer;
    }

    @Override
    public void delete(Long id) {
        int i = consumerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Consumer consumer) {
        consumer.setModifiedTime(Calendar.getInstance().getTime());
        consumerMapper.updateByPrimaryKeySelective(consumer);
    }

    @Override
    public List<Consumer> findAll() {

        return consumerMapper.selectAll();
    }
}
